package com.topsun.posclient.repository;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

import com.topsun.posclient.finance.view.FinanceView;


public class OpenFinanceAction extends Action implements IWorkbenchAction{
	private IWorkbenchWindow workbenchWindow;

	public OpenFinanceAction(IWorkbenchWindow window) {
		if (window == null) {
			throw new IllegalArgumentException();
		}
		this.workbenchWindow = window;
	}

	public void run() {
		if (workbenchWindow != null) {
			try {
				workbenchWindow.getActivePage().showView(FinanceView.ID, null, IWorkbenchPage.VIEW_ACTIVATE);
			} catch (PartInitException e) {
				e.printStackTrace();
		        MessageDialog.openError(workbenchWindow.getShell(), "Error", "Error in opening view :"+e.getLocalizedMessage());
			}
		}
	}

	public void dispose() {
		workbenchWindow = null;
	}
}
